﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using BuildHelper;
using System.Management;
using System.Globalization;

namespace System
{
    public static class ProcessExt2
    {
        public static void CdDir(this Process pr, string dir)
        {
            string drive = "";
            if (dir != null && dir.Length > 1 && dir[1] == ':')
                drive = dir.Substring(0, 2);
            if (dir != null && dir[0]=='\"' && dir.Length > 2 && dir[2] == ':')
                drive = dir.Substring(1, 2);
            if (drive.IsNotNull())
                pr.Execute(drive);
            if (!dir.StartsWith("\""))
                dir = "\"" + dir;
            if (!dir.EndsWith("\""))
                dir += "\"";
            pr.Execute("cd " + dir);
        }
        public static void EchoOff(this Process pr)
        {
            pr.Execute("@echo off");
        }
        public static void Echo(this Process pr, string msg)
        {
            pr.Execute("echo " + msg);
        }
        public static void CallExit(this Process pr)
        {
            pr.Execute("exit");
        }
        public static void Execute(this Process pr, string str)
        {
            try
            {
                pr.StandardInput.WriteLine(str);
                pr.StandardInput.Flush();
            }
            catch { }
        }
        public static void SafeWaitForExit(this Process p)
        {
            try
            {
                while (!Program.IsExit && !p.HasExited)
                {
                    System.Windows.Forms.Application.DoEvents();
                }
            }
            catch { }
        }
       
        public static void MinimizeProc(this Process process)
        {
            User32.ShowWindow(process.MainWindowHandle, User32.SW_SHOWMINIMIZED);
        }
        public static void MaximizeProc(this Process process)
        {
            User32.ShowWindow(process.MainWindowHandle, User32.SW_MAXIMIZE);
        }
    }
}
